Manipulating Units, Physical Quantities, and Equations

Jason Martinez, Wolfram Alpha LLC

Join the Conversation #WolframTechConf

Unit & Physical Quantity Overview

Wolfram|Alpha and the Wolfram Language contain the world's most extensive collection of computable units

The Wolfram Language "knows" > 25,000 units (including compound units)

The Wolfram Language handles >3,100 physical quantities

Soon to be fully ISO 80000 compliant

The Wolfram Language contains an ever-growing and increasingly powerful set of tools for working with dimensional quantities

Units & Physical Quantities in Wolfram Language

Quantity[1,"KelvinsDifference"]

Quantity[1,"Meters"/"Seconds"]

LinguisticAssistant

QuantityVariable["Molarity"]

QuantityVariable["M","Mass"]

LinguisticAssistant

Custom Physical Quantities & Units

The Wolfram Language can be used to construct new physical quantities from combinations of existing physical quantities, unit dimensions, and completely independent physical quantities.

x=QuantityVariable["x","ElectricPotential"/"Altitude"]

y=QuantityVariable["y",{{"LengthUnit",2},{"MassUnit",-1}}]

Independent Units and Physical Quantities

IndependentPhysicalQuantity

IndependentUnit

IndependentUnitDimension

pq=QuantityVariable["Q",IndependentPhysicalQuantity["Widgets"]]

u=QuantityVariableCanonicalUnit[pq]

Quantity[5,u]

QuantityVariableDimensions[pq]

Translating between Units, Physical Quantities, and Unit Dimension Lists

Parts of Quantities & Quantity Variables

Through[{#&,QuantityVariableIdentifier,QuantityVariablePhysicalQuantity}[QuantityVariable["V","ElectricPotential"]]]

Through[{#&,QuantityMagnitude,QuantityUnit}[Quantity[100,"Kilometers"/"Hours"]]]

UnitDimensions: Translating Quantities to Unit Dimension Lists

Unit dimension lists are list of ordered dimension pairs, indicating the magnitude of a unit or physical quantity in that dimension.

Physical dimensions include: "AmountUnit", "AngleUnit", "ElectricCurrentUnit", "InformationUnit", "LengthUnit", "LuminousIntensityUnit", "MassUnit", "MoneyUnit", "PersonUnit", "SolidAngleUnit",  "TemperatureDifferenceUnit", "TemperatureUnit", and "TimeUnit" as well as IndependentUnitDimension.

UnitDimensions["LargeCalories"]

UnitDimensions[Quantity[1000,"KelvinsDifference"/"Miles"]]

QuantityVariableDimensions: Translating Physical Quantities to Unit Dimensions

QuantityVariableDimensions can be applied to a wide variety of expressions including QuantityVariable including combinations of QuantityVariable and Quantity and derivatives of QuantityVariable.

QuantityVariableDimensions[QuantityVariable["M","Mass"]*Quantity["SpeedOfLight"]^2]

expr=QuantityVariable["f","RadiantFluxDensity"]'[QuantityVariable["T","Time"]]

QuantityVariableDimensions[expr]

QuantityVariableDimensions[QuantityVariable["f","RadiantFluxDensity"]]

QuantityVariableDimensions[Derivative[1,1][QuantityVariable["ψ","Length"^(-1/2)]][QuantityVariable["Time"],QuantityVariable["Length"]]]

Examine the dimensional coefficients of a sampling of electromagnetic physical quantities:

pqs={#,QuantityVariableDimensions[QuantityVariable[#]]}&/@{"ElectricAdmittance","ElectricCapacitance","ElectricCharge","ElectricChargeDensity","ElectricConductivity","ElectricCurrent","ElectricFieldStrength","ElectricPotential","ElectricResistance","ElectricResistivity","MagneticFrequencyShift","MagneticInductance","MagneticInduction"};
dimensions=({#[[1]],{"LengthUnit", "MassUnit", "TimeUnit"}/.MapThread[Rule,Transpose[#[[2]]]]}&/@pqs)/.{"LengthUnit"->0, "MassUnit"->0, "TimeUnit"->0};
Graphics3D[{PointSize[Large],Blue,Tooltip[Point[#[[2]]],#[[1]]]&/@dimensions},Axes->True,Ticks->Table[i,{3},{i,-3,4}],AxesLabel->{"length","mass","time"},BoxRatios->1]

QuantityVariableCanonicalUnit: Translating Physical Quantities to Units

Handles combinations of QuantityVariables and Quantities as well as derivatives of QuantityVariables

Supports IndependentPhysicalQuantity

p=QuantityVariable["P","Pressure"];
a=QuantityVariable["Altitude"];

QuantityVariableCanonicalUnit[p]

QuantityVariableCanonicalUnit[p^2/Quantity["Seconds"]]

QuantityVariableCanonicalUnit[p'[a]]

QuantityVariableCanonicalUnit: Translating Unit Dimension Lists to Units

Unit dimension lists can be used in place of physical quantities

e=QuantityVariable["e",{{"LengthUnit",-(3/2)},{"TimeUnit",-1}}];
QuantityVariableCanonicalUnit[e]

PhysicalQuantityLookup: Translating Units to Physical Quantities

PhysicalQuantityLookup finds the physical quantities corresponding to a unit

PhysicalQuantityLookup can find physical quantities of combinations of units by examining their unit dimensions

PhysicalQuantityLookup["Feet"]//Short

PhysicalQuantityLookup[(Quantity[10, "m", meters, "Meters"]),3]

PhysicalQuantityLookup[(Quantity[55, "mi""/""h", miles per hour, (("Miles")/("Hours"))]),3]

PhysicalQuantityLookup: Translating Unit Dimension Lists to Physical Quantities

PhysicalQuantityLookup[{{"LengthUnit",1},{"TimeUnit",-1}},3]

PhysicalQuantityLookup[{{IndependentUnitDimension["Widgets"],1},{"LengthUnit",1},{"TimeUnit",-1}},3]

Manipulating Expressions along Unit Dimensions

DimensionalCombinations

DimensionalCombinations computes what combinations of QuantityVariables (as well as Quantities) yield an expression with the desired unit dimensions.

DimensionalCombinations[{(QuantityVariable["V", "ElectricPotential"]),(QuantityVariable["I", "ElectricCurrent"]),(QuantityVariable["R", "ElectricResistance"])}]

DimensionalCombinations[{(QuantityVariable["m", "Mass"]),(QuantityVariable["l", "Length"]),(QuantityVariable["t", "Time"]),(QuantityVariable["e", "ElectricCharge"])},((((QuantityVariable["K", "Energy"])^2) (QuantityVariable["V", "ElectricPotential"]))/(QuantityVariable["m", "Mass"]))]

DimensionalCombinations[{(QuantityVariable["f", "Force"]),(QuantityVariable["d", "Distance"]),(QuantityVariable["e", "ElectricCharge"])},IncludeQuantities->{"ElectricConstant"}]

Construct Dimensionless Numbers

There are several parameters of interest for the field of fluid mechanics:

qvs={QuantityVariable["L","Length"],QuantityVariable["η","DynamicViscosity"],QuantityVariable["γ","SurfaceTension"],QuantityVariable["ρ","MassDensity"],QuantityVariable["v","Speed"],QuantityVariable["g","Acceleration"],QuantityVariable["ΔP","Pressure"]}

Examine several dimensionless numbers :

formulanames={"ArchimedesNumber","BoussinesqNumber","EotvosNumber","FroudeNumber",{"BrownellKatzNumber","Viscosity"},{"EulerNumber","PressureDifference"},{"ReynoldsNumber","DynamicViscosity"}};
formulas=Last[FormulaData[#]]&/@formulanames

Construct possible dimensionless numbers:

solutions=DimensionalCombinations[qvs,GeneratedParameters->None]

Grid[Transpose[{formulanames,formulas,{solutions[[8]]^3,solutions[[2]]^-1,solutions[[13]]^2,(1/solutions[[2]])^(1/2),solutions[[3]]*solutions[[13]]^2,solutions[[4]]^-1,solutions[[7]]}}],Frame->All]

Dimensionless Combination of Economic Measures

Determine a list of possible dimensionless price impact functions which  depend on stock price, size and cost of bets, trading volumes and the volatility of the stock:

stockprice=QuantityVariable["P","Money"/IndependentPhysicalQuantity["shares"]];
betsize=QuantityVariable["Q",IndependentPhysicalQuantity["shares"]];
tradingvolume=QuantityVariable["V",IndependentPhysicalQuantity["shares"]/"Time"];
stockvolatility=QuantityVariable["σ",1/Sqrt["Time"]];
betcost=QuantityVariable["C","Money"];

Find the general dimensionless combination:

DimensionalCombinations[{stockprice, betsize, tradingvolume,stockvolatility,betcost}]

Determine specific instances:

dc=DimensionalCombinations[{stockprice, betsize, tradingvolume,stockvolatility,betcost},GeneratedParameters->None]

In A. S. Kyle and A. A. Obizhaev independently derive two dimensionless combinations based on these expressions

{(1/dc[[3]])^(1/3),dc[[1]]^-1/dc[[3]]^-(1/3)}

NondimensionalizationTransform: Transforming Equations

ψ= QuantityVariable["ψ", "WaveFunctionBoundState1DPositionRepresentation"];
𝓍= QuantityVariable["x", "Length"];
𝓂= QuantityVariable["m", "Mass"]; 
ω= QuantityVariable["ω", "Frequency"]; 
ℰ= QuantityVariable["E", "Energy"];

odeHO= -Quantity[1,"ReducedPlanckConstant"]^2/(2𝓂) ψ''[𝓍]+1/2𝓂 (ω^2) (𝓍^(2 ))ψ[𝓍]==ℰ ψ[𝓍]

NondimensionalizationTransform[odeHO,{ψ,𝓍},{Ψ,ξ}]

NondimensionalizationTransform[odeHO,{ψ,𝓍},{Ψ,ξ},"NondimensionalizationRules"]

Natural Units: Black Holes

Clear[k,m,j]

variables=FormulaData[{"BlackHoleSurfaceGravity","Charge","AngularMomentum"},"QuantityVariables"];
formula=FormulaData[{"BlackHoleSurfaceGravity","Charge","AngularMomentum"}]

NondimensionalizationTransform[formula, variables, {k,m,j}]

NondimensionalizationTransform[formula, variables, {k,m,j},UnitSystem->"DeSitterUnits"]

Comparing Natural Unit Systems

Transform Coulomb's Law and Newton's Law of Gravitation using different sets of natural units:

naturalunits={"PlanckUnits","HartreeAtomicUnits","RydbergAtomicUnits","LorentzHeavisideNaturalUnits","GaussianNaturalUnits"};

cleq=First@FormulaData["CoulombsLaw"]

nlogeq=FormulaData["NewtonsLawOfUniversalGravitation"]

coulomb=NondimensionalizationTransform[cleq,{(QuantityVariable["F", "Force"]),(QuantityVariable[(Subscript["Q", 1]), "ElectricCharge"]), (QuantityVariable[(Subscript["Q", 2]), "ElectricCharge"]),(QuantityVariable["r", "Distance"])},{f,q1,q2,R},UnitSystem->#]&/@naturalunits;
gravity=NondimensionalizationTransform[nlogeq,{(QuantityVariable["F", "Force"]), (QuantityVariable[(Subscript["m", 1]), "Mass"]), (QuantityVariable[(Subscript["m", 2]), "Mass"]),(QuantityVariable["r", "Distance"])},{f,m1,m2,R},UnitSystem->#]&/@naturalunits;

Compare how the formulas look under different natural unit systems:

Grid[Prepend[Transpose[{naturalunits,gravity,coulomb}],{"unit system","gravitational force","electrostatic force"}],Dividers->Center]

Further usage of Physical Quantities and Units in the  Wolfram Language

Physical Constants

The "PhysicalConstant" entity domain contains 210 physics, astronomy, chemistry, ... constants with content continuing to be added

helps provide computable content, entity access, and easy updating of constants in WL and W|A

contain details information on standards defining constants, uncertainties, etc.

interconvertible with Quantity via ToEntity and FromEntity

EntityList["PhysicalConstant"]//Length

With[{ents=Take[EntityList["PhysicalConstant"],7]},Grid[EntityValue[ents,{"Entity","CanonicalName","Value"}],Dividers->All,Alignment->Left]]

EntityValue["PhysicalConstant","Properties"]

EntityClassList["PhysicalConstant"]

EntityList[(EntityClass["cosmological constants", EntityClass["PhysicalConstant","Cosmological"], "EntityClass[\"PhysicalConstant\", \"Cosmological\"]", "physical constants"])]

ToEntity[Quantity["BoltzmannConstant"]]//InputForm

FromEntity[(Entity["gravitational constant", Entity["PhysicalConstant","GravitationalConstant"], "Entity[\"PhysicalConstant\", \"GravitationalConstant\"]", "physical constant"])]//InputForm

FormulaData

FormulaData["OhmsLaw"]

FormulaData["OhmsLaw","Association"]

FormulaData["ConeMomentOfInertia","QuantityVariableDimensions","Association"]

Other Domains

(Entity["van der Waals gas", Entity["PhysicalSystem","VanDerWaalsGas"], "Entity[\"PhysicalSystem\", \"VanDerWaalsGas\"]", "physical system"])[(EntityProperty["equation of state", EntityProperty["PhysicalSystem","EquationOfState"], "EntityProperty[\"PhysicalSystem\", \"EquationOfState\"]"])]

EntityList[EntityClass["MeasurementDevice","Pressure"]]

Coming Soon

Formula Repository

http://resources.wolframcloud.com/FormulaRepository

Other Functions and Improvements

KnownPhysicalQuantityQ

UnitConvert with Natural Unit support